//
//  ZUserDefault.m
//  Test
//
//  Created by 徐益智 on 16/4/10.
//  Copyright © 2016年 Vdianjing. All rights reserved.
//

#import "ZUserDefault.h"

@implementation ZUserDefault

#pragma mark 存储对象类型
+(void)storageObject:(id)myMessage Key:(NSString*)mykey
{
    NSUserDefaults *userDefaluts=[NSUserDefaults standardUserDefaults];
    NSString *oldMessage=[userDefaluts objectForKey:mykey];
    if (oldMessage!=nil)
    {
        [userDefaluts removeObjectForKey:mykey];
    }
    [userDefaluts setObject:myMessage forKey:mykey];
    [userDefaluts synchronize];
}

+(id)getStorageObjectWithKey:(NSString *)mykey
{
    if (mykey.length>0 && mykey!=nil)
    {
        NSUserDefaults *userDefaults= [NSUserDefaults standardUserDefaults];
        id myMessage=[userDefaults objectForKey:mykey];
        if (myMessage!=nil){
            return myMessage;
        }
    }
    return nil;
}

#pragma mark 存储BOOL类型
+(void)storageBool:(BOOL)myMessage Key:(NSString*)mykey
{
    NSUserDefaults *userDefaluts = [NSUserDefaults standardUserDefaults];
    [userDefaluts removeObjectForKey:mykey];
    [userDefaluts setBool:myMessage forKey:mykey];
    [userDefaluts synchronize];
}

+(BOOL)getStorageBoolWithKey:(NSString *)mykey
{
    if (mykey.length>0 && mykey!=nil)
    {
        NSUserDefaults *userDefaults= [NSUserDefaults standardUserDefaults];
        BOOL myMessage = [userDefaults boolForKey:mykey];
        return myMessage;
    }
    return nil;
}

#pragma mark 存储基本数据类型
+(void)storageIntager:(NSInteger)myMessage Key:(NSString*)mykey
{
    NSUserDefaults *userDefaluts=[NSUserDefaults standardUserDefaults];
    [userDefaluts removeObjectForKey:mykey];
    [userDefaluts setInteger:myMessage forKey:mykey];
    [userDefaluts synchronize];
}

+(NSInteger)getStorageIntagerWithKey:(NSString *)mykey
{
    if (mykey.length>0 && mykey!=nil)
    {
        NSUserDefaults *userDefaluts=[NSUserDefaults standardUserDefaults];
        NSInteger myMessage = [userDefaluts integerForKey:mykey];
        return myMessage;
    }
    return 0;
}

#pragma mark 删除本地保存的信息: removeKey
+(void)deleteObjectKey:(NSString *)myKey
{
    if (myKey.length > 0 && myKey != nil)
    {
        NSUserDefaults *userDefaults= [NSUserDefaults standardUserDefaults];
        [userDefaults removeObjectForKey:myKey];
    }
}

@end
